package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Mobile        string `gorm:"type:varchar(11);not null;comment:'手机号'"`
	Password      string `gorm:"type:varchar(32);not null;comment:'密码'"`
	HeadImage     string `gorm:"type:varchar(500);;comment:'头像'"`
	NickName      string `gorm:"type:varchar(32);not null;comment:'昵称'"`
	AccountStatus int    `gorm:"type:int(11);default:0;not null;comment:'账号状态,0-正常，1-禁用'"`
}

func (u *User) FindUserByMobile(db *gorm.DB, mobile string) error {
	return db.Debug().Where("mobile = ?", mobile).First(u).Error
}

func (u *User) Register(db *gorm.DB) error {
	return db.Debug().Create(u).Error
}

func (u *User) UpdatePassword(db *gorm.DB) error {
	return db.Debug().Updates(u).Error
}

func (u *User) FindUserById(db *gorm.DB, id int64) error {
	return db.Debug().Where("id = ?", id).Find(u).Error
}

func (u *User) UpdatedUser(db *gorm.DB) error {
	return db.Debug().Updates(u).Error
}
